package com.ymatou.iapi.dglogin.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dglogin.parameter.BindMobileWithVerifyCodeBean;
import com.ymatou.iapi.dglogin.service.BindMobileWithVerifyCodeCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmember.Member;
import com.ymttest.database.sqlwapper.godmember.GodMemberWapper;
import com.ymttest.utils.TestDataManager;
/**
*买家验证码绑定手机号
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_BindMobileWithVerifyCode{
	private static BindMobileWithVerifyCodeBean bindmobilewithverifycodeBean;
	private static BindMobileWithVerifyCodeCall bindmobilewithverifycodeCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("买家验证码绑定手机号");
	}

	@Before
	public void caseUp() {
		bindmobilewithverifycodeBean=new BindMobileWithVerifyCodeBean();
		bindmobilewithverifycodeCall=new BindMobileWithVerifyCodeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(bindmobilewithverifycodeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BindMobileWithVerifyCode_001() {
		Logger.start(true,"买家验证码绑定手机号成功");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			Integer shopId = GodmchManageCallService.CreateSellerMch();
			String mobile=TestDataManager.getPhoneNum();
			String vcode=DGUserCallService.BuyerSendVerifyCodeCall(mobile);
			bindmobilewithverifycodeBean.setMobile(mobile);
			bindmobilewithverifycodeBean.setVerifyCode(vcode);
			bindmobilewithverifycodeBean.setUserId(userId);
			bindmobilewithverifycodeBean.setShopId(shopId);
			bindmobilewithverifycodeCall.setData(bindmobilewithverifycodeBean);
			bindmobilewithverifycodeCall.callService();	
			Logger.verifyEquals("true", bindmobilewithverifycodeCall.getString("success"), "验证success");
			GodMemberWapper DefGodMemberWapper=new GodMemberWapper();
			Member info = DefGodMemberWapper.selectMemberByUserId(userId,shopId).get(0);
			Logger.verifyNotNull(info.getMobile(), "绑定手机号");
			//20200526 现在直接调用不绑定
//			MessageListBean MessageListBean = MqQueryCallService.initGoduserBindMobile(userId);
//			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
//			if(joa.size()==0){
//				Thread.sleep(5000);
//				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
//			}
//			joa.forEach(ele->{
//				Logger.debug(ele.toString());
//			});
//			Logger.verifyEquals(mobile, joa.get(0).get("mobile"), "验证mobile");
//			Logger.verifyEquals(userId, joa.get(0).get("userId"), "验证userId");
//			Logger.verifyEquals(shopId, joa.get(0).get("shopId"), "验证shopId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindMobileWithVerifyCode_002() {
		Logger.start(true,"不输入mobile失败");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			Integer shopId = GodmchManageCallService.CreateSellerMch();
			String mobile=TestDataManager.getPhoneNum();
			String vcode=DGUserCallService.BuyerSendVerifyCodeCall(mobile);
//			bindmobilewithverifycodeBean.setMobile(mobile);
			bindmobilewithverifycodeBean.setVerifyCode(vcode);
			bindmobilewithverifycodeBean.setUserId(userId);
			bindmobilewithverifycodeBean.setShopId(shopId);
			bindmobilewithverifycodeCall.setData(bindmobilewithverifycodeBean);
			bindmobilewithverifycodeCall.callService();	
			Logger.verifyEquals("false", bindmobilewithverifycodeCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindMobileWithVerifyCode_003() {
		Logger.start(true,"不输入userId失败");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			Integer shopId = GodmchManageCallService.CreateSellerMch();
			String mobile=TestDataManager.getPhoneNum();
			String vcode=DGUserCallService.BuyerSendVerifyCodeCall(mobile);
			bindmobilewithverifycodeBean.setMobile(mobile);
			bindmobilewithverifycodeBean.setVerifyCode(vcode);
//			bindmobilewithverifycodeBean.setUserId(userId);
			bindmobilewithverifycodeBean.setShopId(shopId);
			bindmobilewithverifycodeCall.setData(bindmobilewithverifycodeBean);
			bindmobilewithverifycodeCall.callService();	
			Logger.verifyEquals("false", bindmobilewithverifycodeCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindMobileWithVerifyCode_004() {
		Logger.start(true,"不输入shopId失败");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			Integer shopId = GodmchManageCallService.CreateSellerMch();
			String mobile=TestDataManager.getPhoneNum();
			String vcode=DGUserCallService.BuyerSendVerifyCodeCall(mobile);
			bindmobilewithverifycodeBean.setMobile(mobile);
			bindmobilewithverifycodeBean.setVerifyCode(vcode);
			bindmobilewithverifycodeBean.setUserId(userId);
//			bindmobilewithverifycodeBean.setShopId(shopId);
			bindmobilewithverifycodeCall.setData(bindmobilewithverifycodeBean);
			bindmobilewithverifycodeCall.callService();	
			Logger.verifyEquals("false", bindmobilewithverifycodeCall.getString("success"), "验证success");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindMobileWithVerifyCode_005() {
		Logger.start(true,"不输入verifyCode失败");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			Integer shopId = GodmchManageCallService.CreateSellerMch();
			String mobile=TestDataManager.getPhoneNum();
			String vcode=DGUserCallService.BuyerSendVerifyCodeCall(mobile);
			bindmobilewithverifycodeBean.setMobile(mobile);
//			bindmobilewithverifycodeBean.setVerifyCode(vcode);
			bindmobilewithverifycodeBean.setUserId(userId);
			bindmobilewithverifycodeBean.setShopId(shopId);
			bindmobilewithverifycodeCall.setData(bindmobilewithverifycodeBean);
			bindmobilewithverifycodeCall.callService();	
			Logger.verifyEquals("false", bindmobilewithverifycodeCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindMobileWithVerifyCode_006() {
		Logger.start(true,"verifyCode错误失败");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			Integer shopId = GodmchManageCallService.CreateSellerMch();
			String mobile=TestDataManager.getPhoneNum();
			String vcode=DGUserCallService.BuyerSendVerifyCodeCall(mobile);
			bindmobilewithverifycodeBean.setMobile(mobile);
			bindmobilewithverifycodeBean.setVerifyCode(vcode+1);
			bindmobilewithverifycodeBean.setUserId(userId);
			bindmobilewithverifycodeBean.setShopId(shopId);
			bindmobilewithverifycodeCall.setData(bindmobilewithverifycodeBean);
			bindmobilewithverifycodeCall.callService();	
			Logger.verifyEquals("false", bindmobilewithverifycodeCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindMobileWithVerifyCode_007() {
		Logger.start(true,"同一个shopId绑定同一个手机号多次失败");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			UserCreateBean usercreateBean2 = DGUserCallService.initUsercreateBean();
			int userId2 = DGUserCallService.UserCreateCall(usercreateBean2);
			Integer shopId = GodmchManageCallService.CreateSellerMch();
			String mobile=TestDataManager.getPhoneNum();
			String vcode=DGUserCallService.BuyerSendVerifyCodeCall(mobile);
			bindmobilewithverifycodeBean.setMobile(mobile);
			bindmobilewithverifycodeBean.setVerifyCode(vcode);
			bindmobilewithverifycodeBean.setUserId(userId);
			bindmobilewithverifycodeBean.setShopId(shopId);
			bindmobilewithverifycodeCall.setData(bindmobilewithverifycodeBean);
			bindmobilewithverifycodeCall.callService();	
			Logger.verifyEquals("true", bindmobilewithverifycodeCall.getString("success"), "验证success");
			String vcode2=DGUserCallService.BuyerSendVerifyCodeCall(mobile);
			bindmobilewithverifycodeBean.setUserId(userId2);
			bindmobilewithverifycodeBean.setVerifyCode(vcode2);
			bindmobilewithverifycodeCall.callService();	
			Logger.verifyEquals("false", bindmobilewithverifycodeCall.getString("success"), "验证success");
			Logger.verifyEquals("111", bindmobilewithverifycodeCall.getString("errorCode"), "验证errorCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindMobileWithVerifyCode_008() {
		Logger.start(true,"同一个shopId绑定同一个userId多次失败");
		try {
			//手机号换了
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			Integer shopId = GodmchManageCallService.CreateSellerMch();
			String mobile=TestDataManager.getPhoneNum();
			String vcode=DGUserCallService.BuyerSendVerifyCodeCall(mobile);
			bindmobilewithverifycodeBean.setMobile(mobile);
			bindmobilewithverifycodeBean.setVerifyCode(vcode);
			bindmobilewithverifycodeBean.setUserId(userId);
			bindmobilewithverifycodeBean.setShopId(shopId);
			bindmobilewithverifycodeCall.setData(bindmobilewithverifycodeBean);
			bindmobilewithverifycodeCall.callService();	
			String t1=bindmobilewithverifycodeCall.getString("accessToken");
			Thread.sleep(5000);
			String mobile2=TestDataManager.getPhoneNum();
			String vcode2=DGUserCallService.BuyerSendVerifyCodeCall(mobile2);
			bindmobilewithverifycodeBean.setMobile(mobile2);
			bindmobilewithverifycodeBean.setVerifyCode(vcode2);
			bindmobilewithverifycodeCall.callService();	
			Logger.verifyEquals("true", bindmobilewithverifycodeCall.getString("success"), "验证success");
			String t2=bindmobilewithverifycodeCall.getString("accessToken");
			Logger.verifyNotEquals(t1, t2, "token不同");
			Logger.verifyEquals(AuthCallServiceV2.signAuth(t1).get("UserData"),	AuthCallServiceV2.signAuth(t2).get("UserData"),"用户相同");
			//20200526 现在直接调用不绑定
//			MessageListBean MessageListBean = MqQueryCallService.initGoduserBindMobile(userId);
//			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
//			if(joa.size()==0){
//				Thread.sleep(5000);
//				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
//			}
//			joa.forEach(ele->{
//				Logger.debug(ele.toString());
//			});
//			Logger.verifyEquals(mobile, joa.get(0).get("mobile"), "验证mobile");
//			Logger.verifyEquals(userId, joa.get(0).get("userId"), "验证userId");
//			Logger.verifyEquals(shopId, joa.get(0).get("shopId"), "验证shopId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BindMobileWithVerifyCode_009() {
		Logger.start(true,"买家验证码绑定手机号成功-传入clientIp-deviceId");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			Integer shopId = GodmchManageCallService.CreateSellerMch();
			String mobile=TestDataManager.getPhoneNum();
			String vcode=DGUserCallService.BuyerSendVerifyCodeCall(mobile);
 			bindmobilewithverifycodeBean.setClientIp(TestDataManager.getRandomIp().toLowerCase());
			bindmobilewithverifycodeBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			bindmobilewithverifycodeBean.setMobile(mobile);
			bindmobilewithverifycodeBean.setVerifyCode(vcode);
			bindmobilewithverifycodeBean.setUserId(userId);
			bindmobilewithverifycodeBean.setShopId(shopId);
			bindmobilewithverifycodeCall.setData(bindmobilewithverifycodeBean);
			bindmobilewithverifycodeCall.callService();	
			Logger.verifyEquals("true", bindmobilewithverifycodeCall.getString("success"), "验证success");
			//20200526 现在直接调用不绑定
//			MessageListBean MessageListBean = MqQueryCallService.initGoduserBindMobile(userId);
//			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
//			if(joa.size()==0){
//				Thread.sleep(5000);
//				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
//			}
//			joa.forEach(ele->{
//				Logger.debug(ele.toString());
//			});
//			Logger.verifyEquals(mobile, joa.get(0).get("mobile"), "验证mobile");
//			Logger.verifyEquals(userId, joa.get(0).get("userId"), "验证userId");
//			Logger.verifyEquals(shopId, joa.get(0).get("shopId"), "验证shopId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BindMobileWithVerifyCode_010() {
		Logger.start(true,"买家验证码绑定手机号成功-绑定客服");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			Integer shopId = GodmchManageCallService.CreateSellerMch();
			
			UserCreateBean usercreateBean2 = DGUserCallService.initCsUsercreateBean();
			Integer csId = DGUserCallService.UserCreateCall(usercreateBean2);
			GodmchManageCallService.CreateCSCall((int) shopId, csId, 1);
			
			String mobile=TestDataManager.getPhoneNum();
			String vcode=DGUserCallService.BuyerSendVerifyCodeCall(mobile);
			bindmobilewithverifycodeBean.setMobile(mobile);
			bindmobilewithverifycodeBean.setVerifyCode(vcode);
			bindmobilewithverifycodeBean.setUserId(userId);
			bindmobilewithverifycodeBean.setShopId(shopId);
			bindmobilewithverifycodeBean.setCsId(csId);
			bindmobilewithverifycodeCall.setData(bindmobilewithverifycodeBean);
			bindmobilewithverifycodeCall.callService();	
			Logger.verifyEquals("true", bindmobilewithverifycodeCall.getString("success"), "验证success");
			GodMemberWapper DefGodMemberWapper=new GodMemberWapper();
			Member info = DefGodMemberWapper.selectMemberByUserId(userId,shopId).get(0);
			Logger.verifyNotNull(info.getMobile(), "绑定手机号");
			Logger.verifyEquals(csId, info.getCsId(), "验证客服id");
			//20200526 现在直接调用不绑定
//			MessageListBean MessageListBean = MqQueryCallService.initGoduserBindMobile(userId);
//			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
//			if(joa.size()==0){
//				Thread.sleep(5000);
//				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
//			}
//			joa.forEach(ele->{
//				Logger.debug(ele.toString());
//			});
//			Logger.verifyEquals(mobile, joa.get(0).get("mobile"), "验证mobile");
//			Logger.verifyEquals(userId, joa.get(0).get("userId"), "验证userId");
//			Logger.verifyEquals(shopId, joa.get(0).get("shopId"), "验证shopId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BindMobileWithVerifyCode_011() {
		Logger.start(true,"买家验证码绑定手机号成功、增加区号");
		try {
			String AreaCode="86";
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			Integer shopId = GodmchManageCallService.CreateSellerMch();
			String mobile=TestDataManager.getPhoneNum();
			String vcode=DGUserCallService.BuyerSendVerifyCodeCall(mobile);
			bindmobilewithverifycodeBean.setMobile(mobile);
			bindmobilewithverifycodeBean.setMobileAreaCode(AreaCode);
			bindmobilewithverifycodeBean.setVerifyCode(vcode);
			bindmobilewithverifycodeBean.setUserId(userId);
			bindmobilewithverifycodeBean.setShopId(shopId);
			bindmobilewithverifycodeCall.setData(bindmobilewithverifycodeBean);
			bindmobilewithverifycodeCall.callService();	
			Logger.verifyEquals("true", bindmobilewithverifycodeCall.getString("success"), "验证success");
			GodMemberWapper DefGodMemberWapper=new GodMemberWapper();
			Member info = DefGodMemberWapper.selectMemberByUserId(userId,shopId).get(0);
			Logger.verifyNotNull(info.getMobile(), "绑定手机号");
			//20200526 现在直接调用不绑定
//			MessageListBean MessageListBean = MqQueryCallService.initGoduserBindMobile(userId);
//			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
//			if(joa.size()==0){
//				Thread.sleep(5000);
//				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
//			}
//			joa.forEach(ele->{
//				Logger.debug(ele.toString());
//			});
//			Logger.verifyEquals(mobile, joa.get(0).get("mobile"), "验证mobile");
//			Logger.verifyEquals(userId, joa.get(0).get("userId"), "验证userId");
//			Logger.verifyEquals(shopId, joa.get(0).get("shopId"), "验证shopId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BindMobileWithVerifyCode_012() {
		Logger.start(true,"买家验证码绑定手机号成功-多渠道");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			
			UserCreateBean usercreateBean2 = DGUserCallService.initUsercreateBean();
			usercreateBean2.setAppSource(DGUserCallService.getAppSourceCode(5));
			int userId2 = DGUserCallService.UserCreateCall(usercreateBean2);
			
			Integer shopId = GodmchManageCallService.CreateSellerMch();
			String mobile=TestDataManager.getPhoneNum();
			String vcode=DGUserCallService.BuyerSendVerifyCodeCall(mobile);
			bindmobilewithverifycodeBean.setAccessSource(1);
			bindmobilewithverifycodeBean.setMobile(mobile);
			bindmobilewithverifycodeBean.setVerifyCode(vcode);
			bindmobilewithverifycodeBean.setUserId(userId);
			bindmobilewithverifycodeBean.setShopId(shopId);
			bindmobilewithverifycodeCall.setData(bindmobilewithverifycodeBean);
			bindmobilewithverifycodeCall.callService();	
			Logger.verifyEquals("true", bindmobilewithverifycodeCall.getString("success"), "验证success");
			GodMemberWapper DefGodMemberWapper=new GodMemberWapper();
			Member info = DefGodMemberWapper.selectMemberByUserId(userId,shopId).get(0);
			Logger.verifyNotNull(info.getMobile(), "绑定手机号");
			
			
			vcode=DGUserCallService.BuyerSendVerifyCodeCall(mobile);
			bindmobilewithverifycodeBean.setUserId(userId2);
			bindmobilewithverifycodeBean.setAccessSource(5);
			bindmobilewithverifycodeBean.setVerifyCode(vcode);
			bindmobilewithverifycodeCall.callService();	
			Logger.verifyEquals("true", bindmobilewithverifycodeCall.getString("success"), "验证success");
			 DefGodMemberWapper=new GodMemberWapper();
			 info = DefGodMemberWapper.selectMemberByUserId(userId,shopId).get(0);
			Logger.verifyNotNull(info.getMobile(), "绑定手机号");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}